<!DOCTYPE html>
<html class="zh" lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charSet="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <title>优典后台</title>
    <link rel="stylesheet" href="https://at.alicdn.com/t/font_1612704_az359zx03hq.css"/>
    <style type="text/css">
        html, body {
            min-width: 100%;
            width: 100%;
            min-height: 100%;
            height: 100%;
            background: #d86351;
            text-align: center;
            overflow: hidden;
        }

        .login-form {
            width: 300px;
            height: 300px;
            overflow: hidden;
            margin: 0 auto;
            color: #fff;
            position: fixed;

            left: 50%;
            top: 50%;
            margin: -150px 0 0 -150px
        }

        @media screen and (max-width: 375px) {

            .login-form {
                width: 80% !important;
                margin: 0 auto;
                margin-top: 20%;
                position: relative;
                left: 0;
                top: 0;
            }
        }

        .login-form .login-title {
            font-size: 26px;
            height: 50px;
            line-height: 50px;
        }

        .login-form .login-icon .iconfont {
            font-size: 60px;
        }

        .login-form .login-button {
            background: #fff;
            color: #000;
            width: 90%;
            height: 40px;
            line-height: 40px;
            border: 0;
            border-radius: 4px;
            margin-top: 10px;
            color: #d86351;
        }

        .login-form .login-button:hover {
            background: #f3e4e2;
            cursor: pointer;
        }

        .login-form .login-button .icon-loading {
            display: inline-block;
            -webkit-animation: loadingCircle 1s linear infinite;
            animation: loadingCircle 1s linear infinite;
            margin-right: 5px;
        }

        .login-form .login-input {
            height: 45px;
            line-height: 45px;
            width: 100%;
            display: flex;
        }

        .login-form .login-input input {
            height: 35px;
            line-height: 35px;
            width: 90%;
            border: solid 1px #fff;
            border-left: 0;
            background: transparent;
            outline: none;
            color: #fff;
            flex: 1;
            padding: 0;
            border-radius: 0 2px 2px 0;
        }

        .login-form .login-input .input-placeholder {
            color: #ffffff9c;
            position: absolute;
            left: 30px;
            height: 35px;
            line-height: 35px;
            font-size: 13px;
        }

        .login-form .login-input .login-input-icon {
            flex: 1;
            max-width: 30px;
            height: 35px;
            line-height: 35px;
            border: solid 1px #fff;
            border-right: 0;
            text-align: center;
            border-radius: 2px 0 0 2px;
        }

        .login-form .login-err {
            height: auto;
            overflow: hidden;
            max-height: 25px;
            line-height: 25px;
            text-align: left;
        }

        @-webkit-keyframes loadingCircle {
            to {
                transform: rotate(1turn)
            }
        }

        @keyframes loadingCircle {
            to {
                transform: rotate(1turn)
            }
        }

        .hide {
            display: none !important;
        }
    </style>
</head>
<body>
<div class="login-form">
    <div class="login-icon">
        <i class="iconfont icon-user"></i>
    </div>
    <div class="login-title">优典后台登录</div>
    <form>
        <div class="login-input">
            <div class="login-input-icon">
                <i class="iconfont icon-username"></i>
            </div>
            <input type="text" id="user_name" name="username" placeholder="">
            <div class="input-placeholder">用户名</div>
        </div>
        <div class="login-input">
            <div class="login-input-icon">
                <i class="iconfont icon-mima"></i>
            </div>
            <input type="password" id="password" name="password" placeholder="">
            <div class="input-placeholder">密码</div>
        </div>
        <div class="login-err"></div>
        <button class="login-button" type="button" id="btn-login"><i class="iconfont icon-loading hide"></i> 登录</button>
    </form>

</div>
<script src="/js/jquery-3.6.0.min.js"></script>
<script>
    $(function () {
        $("form").on("keyup",function(e){
            if(e.keyCode===13){
                $("#btn-login").click()
            }
        })
        var inputChange = function () {
            var v = $(this).val(),
                ph = $(this).parent().find(".input-placeholder");
            if (v.length > 0) {
                ph.hide()
            } else {
                ph.show()
            }
        }
        $("input").on("input", inputChange)
        $("#btn-login").on("click", function () {
            var msg = "很抱歉，密码有误，请检查密码。"
            var formData = {
                    user_name: $("#user_name").val(),
                    password: $("#password").val(),
                },
                loadingIcon = $(this).find("i");
            if (formData.user_name.length <= 0 || formData.password.length <= 0) {
                $(".login-err").text("用户名与密码不能为空!")
                return
            }
            loadingIcon.removeClass("hide");
            $.ajax({
                url: "/login/do",
                type: "POST",
                data: JSON.stringify(formData),
                dataType: "json",
                contentType: "application/json",

            }).done(function (r) {
                console.log(r)
                if (r.code === 0) {
                    sessionStorage.setItem("sid",r.result.sid)
                    window.location.href = "/";
                } else {
                    $(".login-err").text(r.msg)
                }

            }).fail(function (e) {
                console.log(e)
                $(".login-err").text("发生异常, 请重新尝试!")
            }).always(function(){
                loadingIcon.addClass("hide");
            })
        })
    })
</script>
</body>
</html>